Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unblock wallet_switchEthereumChain #2634

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Aug 13, 2024

This removes wallet_switchEthereumChain from the BLOCKED_RPC_METHODS list.

Closes MetaMask/MetaMask-planning#2938.
Closes #2654.

Blocked by:

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.91%. Comparing base (f5e359f) to head (99d42da).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2634   +/-   ##
=======================================
  Coverage   94.90%   94.91%           
=======================================
  Files         504      505    +1     
  Lines       11119    11134   +15     
  Branches     1708     1711    +3     
=======================================
+ Hits        10553    10568   +15     
  Misses        566      566           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mrtenz Mrtenz marked this pull request as ready for review August 13, 2024 07:27
@Mrtenz Mrtenz requested a review from a team as a code owner August 13, 2024 07:27
@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from 2a66d50 to fd11f16 Compare August 21, 2024 11:01
@Mrtenz
Copy link
Member Author

Mrtenz commented Aug 21, 2024

@metamaskbot update-pr

Copy link

socket-security bot commented Aug 21, 2024

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] 🔁 npm/@metamask/[email protected] None +1 730 kB metamaskbot
npm/[email protected] 🔁 npm/[email protected] None 0 86.2 kB pimterry

View full report↗︎

Copy link

socket-security bot commented Aug 21, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@Mrtenz
Copy link
Member Author

Mrtenz commented Aug 21, 2024

@SocketSecurity ignore npm/@metamask/[email protected]

This is ours.

@Mrtenz Mrtenz marked this pull request as draft August 21, 2024 11:36
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we could consider full support for wallet_switchEthereumChain, and actually updating the provider configuration etc., but for now this simply makes the wallet_switchEthereumChain method always return null.

Mrtenz added a commit that referenced this pull request Oct 8, 2024
This adds a `isSnapId` function which accepts any value, and returns a
boolean if the input is a valid Snap ID or not.

This is extracted from #2634.
@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from f2aa83e to 1dcbeda Compare January 15, 2025 11:46
@Mrtenz
Copy link
Member Author

Mrtenz commented Jan 15, 2025

@SocketSecurity ignore npm/[email protected]

Only used for development / testing, and pending update in another PR.

@SocketSecurity ignore npm/@metamask/[email protected]

This is ours.

* @param newPermissions - The new permissions to be granted.
* @returns The permissions to grant to the Snap.
*/
#getPermissionsToGrant(snapId: SnapId, newPermissions: RequestedPermissions) {
Copy link
Member

@FrederikBolding FrederikBolding Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? I thought we were making changes elsewhere for the auto granting?

In addition, this endowment has been removed in favor of the CAIP-25 endowment AFAIK

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We grant permission when calling wallet_switchEthereumChain, but still need to grant permission for some network when first installing or updating the Snap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Can we document this?

@@ -207,6 +223,9 @@ async function signTypedData(message: string, from: string) {
* @see https://docs.metamask.io/snaps/reference/rpc-api/#wallet_invokesnap
*/
export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
const { chainId = '0x1' } = (request.params as BaseParams) ?? {};
await switchChain(chainId);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not a problem, but i think always using mainnet makes it possible in the extension e2e tests that use this snap to try to hit the mainnet infura endpoint, but I think that's probably only the case if something triggers getGasPrice and i'm not certain there is an extension e2e test that does that. Just pointing this out in case I am wrong

@jiexi
Copy link

jiexi commented Jan 21, 2025

sorry, I realize this PR is still marked as draft, so sorry for the early nit comments

@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from 736f8f1 to afa3bc5 Compare February 12, 2025 10:49
@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from 607162c to 5e27ac2 Compare February 12, 2025 12:54
@Mrtenz Mrtenz marked this pull request as ready for review February 13, 2025 09:34
@@ -5330,6 +5330,216 @@ describe('SnapController', () => {
snapController.destroy();
});

it('grants the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider` if the `useCaip25Permission` feature flag is enabled', async () => {
Copy link
Member

@FrederikBolding FrederikBolding Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some tests for updating a Snap? That it also grants the permission and maybe revokes the permission as well? I can't recall what happens to eth_accounts normally actually

@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from 3612252 to ff78991 Compare February 21, 2025 09:37
@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from ff78991 to a757d23 Compare February 21, 2025 09:38
@Mrtenz Mrtenz force-pushed the mrtenz/unblock-wallet_switchEthereumChain branch from 2fb2569 to 99d42da Compare February 21, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add wallet_switchEthereumChain support to snaps-jest
3 participants